package carddemo;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: MENG
 * Date: 2022-06-29
 * Time: 21:00
 */
class Card{
    public int rank; //点数
    public String suit; //花色

    public Card(int rank, String suit) {
        this.rank = rank;
        this.suit = suit;
    }

    @Override
    public String toString() {
        return ""+suit+" "+rank;
    }


}

public class CardDemo {
    //生成13个数字，4中花色共52张牌的牌桌
    public static final String[] suits = {"♥","♠","♣","♦"};
    public List<Card> buyDeskCard(){
        List<Card> cards = new ArrayList<>();
        for (int i = 1; i <= 13; i++) {
            for (int j = 0; j < 4; j++) {
                Card card = new Card(i,suits[j]);
                cards.add(card);
            }
        }
        return cards;
    }

    //随机生成牌，也就是随机交换两个牌
    public void shuffle(List<Card> cards){
        for (int i = cards.size()-1; i > 0; i--) {
            Random random = new Random();
            int index = random.nextInt(i);
            swap(cards, i, index);
        }
    }
    //交换两个牌
    public void swap(List<Card> cards, int i, int index){
        Card tmp = cards.get(i);
        cards.set(i,cards.get(index));
        cards.set(index,tmp);

    }

    public List<List<Card>> test(List<Card> cards){
        List<Card> hand1 = new ArrayList<>();
        List<Card> hand2 = new ArrayList<>();
        List<Card> hand3 = new ArrayList<>();

        //建一个新的ArrayList来存放hand1~hand3
        List<List<Card>> hands = new ArrayList<>();
        hands.add(hand1);
        hands.add(hand2);
        hands.add(hand3);

        //3个人，每个人5张牌，轮流抓牌
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                Card card = cards.remove(0);
                hands.get(j).add(card);
            }
        }
        return hands;

    }

}